<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>品牌列表</title>
    <link href="../../lib/layui-v2.6.3/css/layui.css" media="all" rel="stylesheet">
    <link href="../../css/public.css" media="all" rel="stylesheet">
    <link href="../../css/diy/form1.css" rel="stylesheet">
    <script src="../../lib/layui-v2.6.3/layui.js"></script>
    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="../../frontstatic/js/notify.js"></script>
    <script src="../../frontstatic/js/notify_stand.js"></script>
</head>
<body>
<div id="BrandTableDiv">
    <form class="layui-form" style="padding-top: 30px" action="" lay-filter="example">
        <div class="layui-inline">
            <label class="layui-form-label">类别名称：</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" name="commtityName" placeholder="请输入" type="text">
            </div>
        </div>
        <div class="layui-form-item" style="position: relative;right: 1100px" id="selectBtn">
            <div class="layui-input-block">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="layui-btn layui-btn-normal" id="selectwhereBtn" type="button">查询
            </button>
                <button class="layui-btn layui-btn-primary  layui-btn-sm" type="reset">重置</button>
            </div>
        </div>

    </form>
    <button class="layui-btn layui-btn-normal layui-btn-sm" id="BrandaddBtn" type="button" style="position: relative;top: 64px;left: 950px"><i class="layui-icon"></i></button>
    <div style="width: 1550px;margin-top: 40px">
        <table class="layui-table" id="brandTable" lay-filter="BrandTable" lay-skin="nob"></table>
    </div>
</div>
</body>
<script id="BrandDemo" type="text/html">
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    var notify;
    layui.use(['notify'],function(){
        notify=layui.notify;
    })
    layui.use(['table','form'], function () {
        var table = layui.table;
        var form=layui.form;
        var layer = layui.layer;
     var tableIns= table.render({
            elem: '#brandTable'
            , method: 'post'
            , title: '商品数据表'
            , url: '/brand/page' //数据接口
            , page: {theme: '#1E9FFF'}
            , limit: 10
            ,toolbar:true
            ,defaultToolbar: ['filter', 'exports',{
                title: '商品数据表'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records//解析数据列表
                };
            }
            , request: {
                pageName: 'curr' // 页码的参数名称，默认：page
                , limitName: 'nums' //每页数据量的参数名，默认：limit
            }
            , cols: [[ //表头
                {type: 'numbers', title: '序号'}
                , {field: 'name', title: '品牌名称'}
                , {field: 'createTime', title: '创建时间'}
                , {fixed: 'right', title: '操作', toolbar: '#BrandDemo'}
            ]]
        });
        $("#BrandaddBtn").on('click', function () {
            layer.open({
                type: 2,
                title: '品牌添加',
                shadeClose: true,
                shade: 0.8,
                anim: 4,
                area: ['400px', '350px'],
                content: 'brand_add.html',
                end:function() {
                    location.reload();
                }
            });
        })
        //监听工具条
        table.on('tool(BrandTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除该商品类别吗？', function (index) {
                    $.post("/brand/delete", {"id": data.id}, function (re) {
                        if (re.code==0) {
                            notify.success(re.msg)
                            obj.del();
                            layer.close(index);
                        } else{
                            notify.error(re.msg)
                        }
                    })
                });
            }
        });
        $("#selectwhereBtn").on('click', function() {
            var data = form.val('example');
            var orderDate = {
                "name": data.commtityName,
            }
            tableIns.reload({
                where:orderDate
                ,page: {
                    curr: 1
                }
            });
        })
    })
</script>
</html>